﻿/**
 * @author sminutoli
 */
import com.dinmax.flash.draw.cabeza.*
import com.dinmax.flash.central.action.*
import com.dinmax.flash.central.communication.Communication

class com.dinmax.flash.central.bridge.FINDPERSONFormBridge
extends ControlCabeza
implements SelectedListener, ChangedListener {
	
	private var mcNameField:FieldCabeza;
	private var mcLastNameField:FieldCabeza;
	private var mcPhoneField:FieldCabeza;
	private var mcNickField:FieldCabeza;
	
	private var mcAccept:ButtonCabeza;
		
	public function initChild(control:ControlCabeza):Void {
		control.addListener(this);
		switch(control){
			case this.mcNameField:
			FieldCabeza(control).setLabel("Nombre");
			FieldCabeza(control).setValue("");
			break;
			
			case this.mcLastNameField:
			FieldCabeza(control).setLabel("Apellido");
			FieldCabeza(control).setValue("");
			break;
			
			case this.mcPhoneField:
			FieldCabeza(control).setLabel("Telefono");
			FieldCabeza(control).setValue("");
			break;
			
			case this.mcNickField:
			FieldCabeza(control).setLabel("Nick");
			FieldCabeza(control).setValue("");
			break;
			
		};	
		return;
	};
	
	public function selected(control:ControlCabeza):Void {
		switch(control){
			case this.mcAccept:
			Communication.getActive().sendAction(this.createQuery());
			this.selectEvent();
			break;
		};
		return;
	};
		
	public function changed(control:ControlCabeza, type:String):Void {
		//trace("changed "+control);
		
		return;
	};
	
	private function createQuery():ActionGetPersons {
		return new ActionGetPersons(this.mcNameField.getValue(), this.mcLastNameField.getValue(), this.mcNickField.getValue(), Number(this.mcPhoneField.getValue()));
	};
	
};